


var show_change = document.getElementsByClassName("show_change")
var show_box = document.getElementById("show_box")
var hide_btu = document.getElementById("hide_btu")
var dzz = document.getElementById("dzz")


for (let i = 0; i < show_change.length; i++) {
    show_change[i].addEventListener('click',function () {
        // console.log(1);
        show_box.style.display = "block";
        dzz.style.display = "block";
    })
    
}

hide_btu.addEventListener('click',function () {
    show_box.style.display = "none"
    dzz.style.display = "none";
})


// ------------------------------------------------------------------

// 请求数据
getInfo()
function getInfo() {
    commonAjax(null,"https://jsonplaceholder.typicode.com/users",geti)
}

// 处理数据
function geti(data){
    data = data.slice(0,6);
    console.log(data);
    for (var i = 0;i < data.length;i++) {
        var temp = `<li>
                        <div>${data[i].id}</div>
                        <div>${data[i].username}</div>
                        <div>${data[i].phone}</div>
                        <div>${data[i].email}</div>
                        <div>
                            <button 
                            class="show_change" 
                            info_id="${data[i].id}"
                            info_name="${data[i].username}"
                            info_pass="${data[i].phone}"
                            info_is_admin="${data[i].email}" >
                            修改</button>
                            <button
                            info_id="${data[i].id}"
                            class="delete_btu">删除</button>
                        </div>
                    </li>`
        $("#det_info_list").append(temp);
    }
}

// 修改按钮
$("#det_info_list").on('click',".show_change",function () {
    show_box.style.display = "block";
    dzz.style.display = "block";
    $("#user_id").attr('value',$(this).attr('info_id'))
    $("#user_name").attr('value',$(this).attr('info_name'))
    $("#user_pass").attr('value',$(this).attr('info_pass'))
    $("#user_is_admin").attr('value',$(this).attr('info_is_admin'))    
})

// 点击确定修改
var delete_sure = document.getElementById("delete_sure")
delete_sure.addEventListener('click',function () {
    go_update ()
})

// 修改操作
function go_update () {
    commonAjax_post(id, deturl, function (res) {
        console.log(res); 
     })
}

// 删除按钮
$("#det_info_list").on('click',".delete_btu",function () {
    console.log($(this).attr('info_id'));
    // 掉删除操作
})
// 删除操作
function go_delete (id) {
    commonAjax_post(id, deturl, function (res) {
       console.log(res); 
    })
}